//
//  YFShopAdViewCell.m
//  QuanJieShopProject
//
//  Created by apple on 2018/4/14.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFShopAdViewCell.h"
@interface YFShopAdViewCell()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;    // 店名
@property (nonatomic, strong) UILabel *numberLabel;  // 消费人数
@end

@implementation YFShopAdViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor randomColor];
        [self makeView:frame];
    }
    return self;
}

- (void)makeView:(CGRect)frame {
    
    
    // 店铺名字/类型 就是一个图片
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.frame = CGRectMake(0, 0, frame.size.width, frame.size.width);
    [self.contentView addSubview:imgView];
    imgView.image = [UIImage imageNamed:@"noImage"];
    self.imgView = imgView;
    
    // 10是底部间距
    CGFloat labelH = (frame.size.height - imgView.mj_h - 5)/2.f;
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.frame = CGRectMake(0, CGRectGetMaxY(imgView.frame), frame.size.width, labelH);
    nameLabel.text = @"武昌鱼";
    nameLabel.textColor = [UIColor colorWithHexString:@"666666"];
    nameLabel.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    
    UILabel *numberLabel = [[UILabel alloc] init];
    numberLabel.frame = CGRectMake(0, CGRectGetMaxY(nameLabel.frame), frame.size.width, labelH);
    numberLabel.text = @"124人消费";
    numberLabel.textColor = [UIColor colorWithHexString:@"666666"];
    numberLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:numberLabel];
    self.numberLabel = numberLabel;
}
// NearADModel
- (void)setModel:(NearShopModel *)model {
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",NET_BASEURL,model.image_url_thumb]] placeholderImage:[UIImage imageNamed:@"noImage"]];
    
    self.nameLabel.text = model.shop_name;
    NSString *numberStr = [NSString stringWithFormat:@"%@人消费", model.consume_amount];
    self.numberLabel.attributedText = [self changeColorWithStr:numberStr];

    _model = model;
}

- (NSMutableAttributedString *)changeColorWithStr:(NSString *)str{
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str];
    NSRange colorRange = NSMakeRange(0, str.length -3);
    [attStr addAttribute:NSForegroundColorAttributeName value:YFColor_Red range:(colorRange)];
    return attStr;
}

@end
